package org.argetr.resim.proc.math;

import java.awt.image.renderable.ParameterBlock;

import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;

import org.argetr.resim.proc.ConnectionRule;
import org.argetr.resim.proc.data.Const1DArrayDA;
import org.argetr.resim.proc.data.ConverterUT;
import org.argetr.resim.proc.data.Data;
import org.argetr.resim.proc.data.ImageDA;




public class MeanPR extends MathPR {
	protected void setConnectionRules(ConnectionRule connRule){
		connRule.addInType(ImageDA.class, 0);
		connRule.addOutType(Const1DArrayDA.class);
	}
	public Data process() {
		PlanarImage im = getInputAsPlanarImage();
		ParameterBlock pb = new ParameterBlock();
		pb.addSource(im);   // The source image
		pb.add(null);       // null ROI means whole image
		pb.add(1);          // check every pixel horizontally
		pb.add(1);          // check every pixel vertically
		// Perform the mean operation on the source image.
		PlanarImage oim = JAI.create("mean", pb, null);
		// Retrieve and report the mean pixel value.
		double[] mean = (double[])oim.getProperty("mean");

		Data o = new Const1DArrayDA(ConverterUT.get1DFloatArray(mean));
		setOutput(o);
		return getOutput();
	}
}
